package com.one.blocks.rbac.util;

import com.one.blocks.rbac.security.RbacUserDetails;
import lombok.experimental.UtilityClass;
import org.springframework.security.core.context.SecurityContextHolder;

import java.time.LocalDateTime;

/**
 * @author <a href="mailto:idler41@163.con">linfuxin</a> created on 2023-09-24 14:45:36
 */
@UtilityClass
public class SubjectHelper {

    public Integer getSubjectId() {
        return ((RbacUserDetails) SecurityContextHolder.getContext().getAuthentication().getDetails()).getUserId();
    }

    public LocalDateTime getAccessTime() {
        return ((RbacUserDetails) SecurityContextHolder.getContext().getAuthentication().getDetails()).getAccessTime();
    }
}
